package controller.editor;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

import com.mxgraph.swing.mxGraphComponent;

public class ExportToJPGController extends JDialog{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ExportToJPGController(){
		
	}
	
	private static ExportToJPGController instance = null;
	
	public static ExportToJPGController getInstance(){
		if (instance == null){
			instance = new ExportToJPGController();
		}
		return instance;
	}

	public void exportScreen(String directorioActual, String fileName, mxGraphComponent areaDeImpresion)
			throws Exception {
		BufferedImage bi = new BufferedImage(areaDeImpresion.getViewport().getWidth(), areaDeImpresion.getViewport()
				.getHeight(), BufferedImage.TYPE_INT_ARGB);
		Graphics g = bi.createGraphics();
		areaDeImpresion.getViewport().paint(g);
		g.dispose();
			
		ImageIO.write(bi, "png", new File(directorioActual,fileName + ".jpg"));
		
		JOptionPane.showMessageDialog(this,"Exportacion Correcta", "",
                JOptionPane.INFORMATION_MESSAGE);
					
	}

}
